package com.juzi.wopu.query;

import java.util.ArrayList;

import org.apache.commons.lang3.StringUtils;

public class LeaderQuery extends BaseQuery{
	
	private Integer userId;
	private String userName;
	private String mobile;
	private Integer companyId;
	private String companyName;
	private Integer roleId;
	private String roleName;
	
	public final static String domainSql="(SELECT tSysUser.iId AS userId, "
			+ "tSysUser.sUserNo AS userName,tSysUser.sMobile AS mobile, "
			+ "tSysUserRole.iCompany AS companyId, tSysCode.sName AS companyName,"
			+ "tSysRole.sName AS roleName, tSysRole.iId AS roleId FROM "
			+ "dbo.tSysUser AS tSysUser,dbo.tSysUserRole AS tSysUserRole,"
			+ "dbo.tSysCode AS tSysCode,dbo.tSysRole AS tSysRole "
			+ "where tSysUser.iId = tSysUserRole.iUserId and "
			+ "tSysCode.iId=tSysUserRole.iCompany and "
			+ "tSysRole.iId=tSysUserRole.iRole and tSysRole.iId=19) AS"; 

	public LeaderQuery() {
		super(domainSql);
		this.setCountHql(new StringBuilder("select count(*) from "+domainSql +" o"));
		this.setLimitHql(new StringBuilder("select * from "+ domainSql+" o"));
		this.setWhere(new StringBuilder());
		this.setParamList(new ArrayList<>());
	}

	@Override
	protected void addWhere() {
		if(userId !=null && userId != -1){
			AddWhere("o.userId=?", userId);
		}
		
		if(StringUtils.isNotBlank(userName)){
			AddWhere("o.userName like ?","%"+userName+"%");
		}
		  
		if(StringUtils.isNotBlank(mobile)){
			AddWhere("o.mobile like ?","%"+mobile+"%");
		}
		
		if(companyId !=null && companyId != -1){
			AddWhere("o.companyId=?", companyId);
		}
		
		if(StringUtils.isNotBlank(companyName)){
			AddWhere("o.companyName like ?","%"+companyName+"%");
		}
		
		if(roleId !=null && roleId != -1){
			AddWhere("o.roleId=?", roleId);
		}
		
		if(StringUtils.isNotBlank(roleName)){
			AddWhere("o.roleName like ?","%"+roleName+"%");
		}
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public String getCompanyName() {
		return companyName;
	}

	public void setCompanyName(String companyName) {
		this.companyName = companyName;
	}

	public String getRoleName() {
		return roleName;
	}

	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}

	public Integer getUserId() {
		return userId;
	}

	public void setUserId(Integer userId) {
		this.userId = userId;
	}

	public Integer getCompanyId() {
		return companyId;
	}

	public void setCompanyId(Integer companyId) {
		this.companyId = companyId;
	}

	public Integer getRoleId() {
		return roleId;
	}

	public void setRoleId(Integer roleId) {
		this.roleId = roleId;
	}	
}